#!/bin/bash

# filename: PythonEnv_Config.sh

# install the python-dev in system
sudo apt-get install python-dev ;
sudo apt-get install ipython ;
sudo apt-get install python3-dev ;
sudo apt-get install ipython3 ;
sudo apt-get install python-mysqldb;

#------- install pip---------{
#download pip

#check the python workspace exists or create it
if [[ ! -d ~/pythonworkspace  ]]; then
    mkdir ~/pythonworkspace
fi
cd ~/pythonworkspace
#remove the previous get-pip.py install file
if [[ -f ./get-pip.py ]]; then
    rm get-pip.py
fi
wget https://bootstrap.pypa.io/get-pip.py
sudo python ./get-pip.py
sudo python3 ./get-pip.py

#}

#---------install virtualenv------{
sudo pip install --upgrade virtualenv
sudo pip3 install --upgrade virtualenv
#}

#---------create virtualenv for python2/3---{


cd ~/pythonworkspace

#check if python2 workspace exists or create it
if [[ -d ./python2  ]]; then
    rm -rf ./python2
fi
virtualenv -p python2 python2
cd ~/pythonworkspace


#check if python3 workspace exists or create it
if [[ -d ~/pythonworkspace/python3  ]]; then
    rm -rf ~/pythonworkspace/python3
fi
virtualenv -p python3 python3
#}

cd ~/pythonworkspace/python2
echo "entering python2 virtualenv and activate the virtual env"
_OLD_VIRTUAL_PATH=$PATH
export _OLD_VIRTUAL_PATH
PATH=/home/theo/pythonworkspace/python2/bin:$PATH
export PATH

source bin/activate
pip install django==1.8
pip install MySQLdb
pip install PyYAML
deactivate
PATH=$_OLD_VIRTUAL_PATH
export PATH

cd ./pythonworkspace/python3
_OLD_VIRTUAL_PATH=$PATH
export _OLD_VIRTUAL_PATH
PATH=/home/theo/pythonworkspace/python3/bin:$PATH
export PATH
source bin/activate
pip install django==1.8
pip install PyMySQL
pip install PyYAML
deactivate
PATH=$_OLD_VIRTUAL_PATH
export PATH
